package com.getpebble.android.framework.endpoint;

import com.getpebble.android.bluetooth.protocol.ProtocolMessage;
import com.getpebble.android.framework.protocol.EndpointId;
import java.util.Collections;
import java.util.EnumSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Set;

public class QueueEndpoint extends Endpoint {
    private static final Set<EndpointId> SUPPORTED_ENDPOINTS = Collections.unmodifiableSet(EnumSet.of(EndpointId.PHONE_VERSION));
    Queue<ProtocolMessage> queue = new LinkedList();

    public Queue<ProtocolMessage> takeMessages() {
        Queue<ProtocolMessage> messages = this.queue;
        this.queue = new LinkedList();
        return messages;
    }

    Set<EndpointId> getSupportedEndpoints() {
        return EnumSet.allOf(EndpointId.class);
    }

    public boolean onReceive(ProtocolMessage protocolMessage) {
        if (this.queue.size() >= 20) {
            this.queue.poll();
        }
        return this.queue.add(protocolMessage);
    }

    public boolean isSupported(EndpointId endpoint) {
        return SUPPORTED_ENDPOINTS.contains(endpoint);
    }
}
